home *** CD-ROM | disk | FTP | other *** search
/ Nautilus 1992 July / Nautilus-3-8 / Nautilus-3-8.bin / Tools & Utilities / Techy Stuff / Source ƒ / egrep-1.5 / grep-src / TransSkel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-25  |  37.1 KB  |  1,476 lines

  1.  
  2. /*
  3.     TransSkel version 2.01 - Transportable application skeleton
  4.     
  5.     TransSkel is public domain and was originally written by:
  6.  
  7.                 Paul DuBois
  8.                 Wisconsin Regional Primate Research Center
  9.                 1220 Capital Court
  10.                 Madison WI  53715-1299  USA
  11.  
  12.     UUCP:        {allegra,uunet}!uwvax!rhesus!dubois
  13.     Internet:    dubois@primate.wisc.edu
  14.             
  15.     Additional changes were made by
  16.         
  17.                 Owen Hartnett
  18.                 OHM Software Company
  19.                 163 Richard Drive
  20.                 Tiverton, RI 02878  USA
  21.             
  22.     UUCP:        {allegra,uunet}!brunix!omh    
  23.     Internet:    omh@cs.brown.edu
  24.     CSNET:        omh@cs.brown.edu.CSNET         
  25.  
  26.     Owen is also responsible for the port to Lightspeed Pascal.
  27.     
  28.     This version of TransSkel written for LightspeedC.  LightspeedC is a
  29.     trademark of:
  30.             THINK Technologies, Inc
  31.             420 Bedford Street  Suite 350
  32.             Lexington, MA  02173  USA
  33.  
  34.     Change history is in TSHistory.c
  35. */
  36.  
  37.  
  38. /*
  39.     The following symbol controls support for dialogs.
  40.     "#define    supportDialogs" enables support.
  41.     "#undef        supportDialogs" disables support.
  42. */
  43.  
  44. # define    supportDialogs
  45.  
  46.  
  47. # ifdef        supportDialogs
  48. #    include    <Dialogs.h>
  49. # else
  50. #    include    <Windows.h>
  51. # endif
  52.  
  53. #include <Events.h>
  54. #include <Menus.h>
  55. #include <Memory.h>
  56. #include <Quickdraw.h>
  57. #include <Desk.h>
  58. #include <DiskInit.h>
  59. #include <Fonts.h>
  60. #include <TextEdit.h>
  61. #include <Dialogs.h>
  62. #include <OSEvents.h>
  63. #include <ToolUtils.h>
  64. #include <Resources.h>
  65. #include "TransSkel.h"
  66.  
  67.  
  68. /*
  69.     Integer and Longint should be typedef'd to the 2-byte and 4-byte
  70.     integer types for the compiler being used.  These are int and long
  71.     for LightspeedC.
  72. */
  73.  
  74. # define    mBarHeight    20    /* menu bar height.  All window sizing
  75.                                code takes this into account */
  76.  
  77.  
  78. /*
  79.     New(TypeName) returns handle to new object, for any TypeName.
  80.     If there is insufficient memory, the result is nil.
  81. */
  82.  
  83. # define    New(x)    (x **) NewHandle ((Size) sizeof (x))
  84.  
  85.  
  86.  
  87. /*
  88.     Window and Menu handler types, constants, variables.
  89.  
  90.     whList and mhList are the lists of window and menu handlers.
  91.     whClobOnRmve and mhClobOnRmve are true if the handler disposal proc
  92.     is to be called when a handler is removed.  They are temporarily set
  93.     false when handlers are installed for windows or menus that already
  94.     have handlers - the old handler is removed WITHOUT calling the
  95.     disposal proc.
  96.  
  97.     Default lower limits on window sizing of 80 pixels both directions is
  98.     sufficient to allow text windows room to draw a grow box and scroll
  99.     bars without having the thumb and arrows overlap.  These values may
  100.     be changed if such a constraint is undesirable with SkelGrowBounds.
  101.     Default upper limits are for the Macintosh, not the Lisa, but are set
  102.     per machine in SkelInit.
  103. */
  104.  
  105. typedef struct WHandler    WHandler;
  106.  
  107. struct WHandler
  108. {
  109.     WindowPtr    whWind;            /* window/dialog to be handled  */
  110.     ProcPtr        whClobber;        /* data structure disposal proc */
  111.     ProcPtr        whMouse;        /* mouse-click handler proc     */
  112.     ProcPtr        whKey;            /* key-click handler proc       */
  113.     ProcPtr        whUpdate;        /* update handler proc          */
  114.     ProcPtr        whActivate;        /* activate event handler proc  */
  115.     ProcPtr        whClose;        /* close "event" handler proc   */
  116.     ProcPtr        whIdle;            /* main loop proc               */
  117. # ifdef    supportDialogs
  118.     ProcPtr        whEvent;        /* event proc                   */
  119. # endif
  120.     Rect        whGrow;            /* limits on window sizing      */
  121.     Boolean        whSized;        /* true = window was resized    */
  122.     Boolean        whFrontOnly;    /* true = idle only when active */
  123.     WHandler    **whNext;        /* next window handler          */
  124. };
  125.  
  126. static WHandler    **whList = nil;
  127. static Boolean    whClobOnRmve = true;
  128. static Rect        growRect = { 80, 80, 512, 342 - mBarHeight };
  129.  
  130. typedef struct MHandler    MHandler;
  131.  
  132. struct MHandler
  133. {
  134.     Integer        mhID;            /* menu id                     */
  135.     ProcPtr        mhSelect;        /* item selection handler proc */
  136.     ProcPtr        mhClobber;        /* menu disposal handler proc  */
  137.     MHandler    **mhNext;        /* next menu handler           */
  138. };
  139.  
  140.  
  141. static MHandler    **mhList = nil;            /* list of menu handlers */
  142. static Boolean    mhClobOnRmve = true;
  143.  
  144.  
  145. /*
  146.     Variables for default Apple menu handler.  appleID is set to 1 if
  147.     SkelApple is called and is the id of the Apple menu, appleAboutProc
  148.     is the procedure to execute if there is an About... item and it's
  149.     chosen from the Apple menu.  If doAbout is true, then the menu
  150.     contains the About... item, otherwise it's just desk accessories.
  151. */
  152.  
  153. static MenuHandle    appleMenu;
  154. static Integer        appleID = 0;
  155. static ProcPtr        appleAboutProc = nil;
  156. static Boolean        doAbout = false;
  157.  
  158.  
  159. /*
  160.     Miscellaneous
  161.  
  162.     screenPort points to the window manager port.
  163.  
  164.     doneFlag determines when SkelMain returns.  It is set by calling
  165.     SkelWhoa(), which is how the host requests a halt.
  166.  
  167.     pBkgnd points to a background procedure, to be run during event
  168.     processing.  Set it with SkelBackground.  If nil, there's no
  169.     procedure.
  170.  
  171.     pEvent points to an event-inspecting hook, to be run whenever an
  172.     event occurs.  Set it with SkelEventHook.  If nil, there's no
  173.     procedure.
  174.  
  175.     eventMask controls the event types requested in the GetNextEvent
  176.     call in SkelMain.
  177.  
  178.     diskInitPt is the location at which the disk initialization dialog
  179.     appears, if an uninitialized disk is inserted.
  180. */
  181.  
  182. static GrafPtr    screenPort;
  183. static Integer    doneFlag = false;
  184. static ProcPtr    pBkgnd = nil;
  185. static Boolean    (*pEvent)() = nil;
  186. static Integer    eventMask = everyEvent;
  187. static Point    diskInitPt = { /* v = */ 120, /* h = */ 100 };
  188.  
  189. static WindowPtr    oldWindow = nil;     
  190. static WHandler        **oldWDHandler = nil;
  191.     
  192.  
  193. # ifdef    supportDialogs
  194.  
  195. /*
  196.     dlogEventMask specifies events that are passed to dialogs.
  197.     Others are ignored.  Standard mask passes, mousedown, keydown,
  198.     autokey, update, activate and null events.  Null events are
  199.     controlled by bit 0 (always forced on).
  200. */
  201.  
  202. static Integer    dlogEventMask = 0x16b;
  203.  
  204. # endif
  205.  
  206. static WHandler **GetWDHandler(WindowPtr theWind);
  207. static WHandler **GetWHandler(WindowPtr theWind);
  208. static WHandler **GetDHandler(DialogPtr theDialog);
  209. static DoMenuCommand(Longint command);
  210. static DoAppleItem(Integer item);
  211. static DoAppleClobber(void);
  212. static DoMouse(WHandler **h, EventRecord *theEvent);
  213. static DoKey(WHandler **h, char ch, Integer mods);
  214. static DoUpdate(WHandler **h);
  215. static DoActivate(WHandler **h, Boolean active);
  216. static DoClose(WHandler **h);
  217. static DoClobber(WHandler **h);
  218. static DoDialog(EventRecord *theEvent);
  219. static TriggerUpdate(WHandler **h, GrafPtr grownPort);
  220. static DoGrow(WHandler **h, GrafPtr growPort, Point startPt);
  221. static DoZoom(WHandler **h, GrafPtr zoomPort, short partCode);
  222. static DoEvent(EventRecord *theEvent);
  223.  
  224.  
  225. /* -------------------------------------------------------------------- */
  226. /*                        Internal (private) Routines                        */
  227. /* -------------------------------------------------------------------- */
  228.  
  229.  
  230. /*
  231.     Get handler associated with user or dialog window.
  232.     Return nil if window doesn't belong to any known handler.
  233.     This routine is absolutely fundamental to TransSkel.
  234. */
  235.  
  236.  
  237. static WHandler **GetWDHandler (WindowPtr theWind)
  238. {
  239. register WHandler    **h;
  240.  
  241.     if (theWind == oldWindow) 
  242.         return(oldWDHandler);        /* return handler of cached window */
  243.  
  244.     for (h = whList; h != nil; h = (**h).whNext)
  245.     {
  246.         if ((**h).whWind == theWind)
  247.         {
  248.             oldWindow = theWind;    /* set cached window and handler */
  249.             oldWDHandler = h;
  250.             return (h);
  251.         }
  252.     }
  253.     return (nil);
  254. }
  255.  
  256.  
  257. /*
  258.     Get handler associated with user window.
  259.     Return nil if window doesn't belong to any known handler.
  260.     The order of the two tests is critical:  theWind might be nil.
  261. */
  262.  
  263. static WHandler **GetWHandler (WindowPtr theWind)
  264. {
  265. register WHandler    **h;
  266.  
  267.     if ((h = GetWDHandler (theWind)) != nil
  268.         && ((WindowPeek) theWind)->windowKind != dialogKind)
  269.     {
  270.             return (h);
  271.     }
  272.     return (nil);
  273. }
  274.  
  275.  
  276. # ifdef    supportDialogs
  277.  
  278. /*
  279.     Get handler associated with dialog window.
  280.     Return nil if window doesn't belong to any known handler.
  281.     The order of the two tests is critical:  theDialog might be nil.
  282. */
  283.  
  284. static WHandler **GetDHandler (DialogPtr theDialog)
  285. {
  286. register WHandler    **h;
  287.  
  288.     if ((h = GetWDHandler (theDialog)) != nil
  289.         && ((WindowPeek) theDialog)->windowKind == dialogKind)
  290.     {
  291.             return (h);
  292.     }
  293.     return (nil);
  294. }
  295.  
  296. # endif
  297.  
  298.  
  299. /*
  300.     General menu-handler.  Just passes selection to the handler's
  301.     select routine.  If the select routine is nil, selecting items from
  302.     the menu is a nop.
  303. */
  304.  
  305. static DoMenuCommand (Longint command)
  306. {
  307. register Integer    menu;
  308. register Integer    item;
  309. register MHandler    **mh;
  310. register ProcPtr    p;
  311.  
  312.     menu = HiWord (command);
  313.     item = LoWord (command);
  314.     for (mh = mhList; mh != nil; mh = (**mh).mhNext)
  315.     {
  316.         if ((menu == (**mh).mhID) && ((p = (**mh).mhSelect) != nil))
  317.         {
  318.             ((void (*)(Integer)) p) (item);
  319.             break;
  320.         }
  321.     }
  322.     HiliteMenu (0);        /* command done, turn off menu hiliting */
  323. }
  324.  
  325.  
  326. /*
  327.     Apple menu handler
  328.     
  329.     DoAppleItem:  If the first item was chosen, and there's an "About..."
  330.     item, call the procedure associated with it (if not nil).  If there
  331.     is no "About..." item or the item was not the first one, then open
  332.     the associated desk accessory.  The port is saved and restored
  333.     because OpenDeskAcc does not always preserve it correctly.
  334.     
  335.     DoAppleClobber disposes of the Apple menu.
  336. */
  337.  
  338.  
  339. static DoAppleItem (Integer item)
  340. {
  341. GrafPtr    curPort;
  342. Str255    str;
  343. Handle    h;
  344.  
  345.     if (doAbout && item == 1)
  346.     {
  347.         if (appleAboutProc != nil)
  348.             ((void (*) (void)) appleAboutProc) ();
  349.     }
  350.     else
  351.     {
  352.         GetPort (&curPort);
  353.         GetItem (appleMenu, item, str);        /* get DA name */
  354.         SetResLoad (false);
  355.         h = GetNamedResource ('DRVR', (ConstStr255Param) str);
  356.         SetResLoad (true);
  357.         if (h != nil)
  358.         {
  359.             ResrvMem (SizeResource (h) + 0x1000);
  360.             (void) OpenDeskAcc (str);            /* open it */
  361.         }
  362.         SetPort (curPort);
  363.     }
  364. }
  365.  
  366. static DoAppleClobber (void) { DisposeMenu (appleMenu); }
  367.  
  368.  
  369. /* -------------------------------------------------------------------- */
  370. /*                        Window-handler routing routines                    */
  371. /*                                                                        */
  372. /*    See manual for discussion of port-setting behavior.  In general,    */
  373. /*    the current port is made to associate with the active window.        */
  374. /*    This is done in DoActivate for non-dialog windows, in DoDialog        */
  375. /*    for dialog windows.                                                    */
  376. /* -------------------------------------------------------------------- */
  377.  
  378.  
  379. /*
  380.     Pass local mouse coordinates, click time, and the modifiers flag
  381.     word to the handler.  Should not be necessary to set the port, as
  382.     the click is passed to the active window's handler.
  383. */
  384.  
  385. static DoMouse (WHandler **h, EventRecord *theEvent)
  386. {
  387. register ProcPtr    p;
  388. Point                thePt;
  389.  
  390.     if (h != nil)
  391.     {
  392.         if ((p = (**h).whMouse) != nil)
  393.         {
  394.             thePt = theEvent->where;    /* make local copy */
  395.             GlobalToLocal (&thePt);
  396.             ((void (*)(Point, Longint, Integer)) p)
  397.                           (thePt, theEvent->when, theEvent->modifiers);        }
  398.     }
  399. }
  400.  
  401.  
  402. /*
  403.     Pass the character and the modifiers flag word to the handler.
  404.     Should not be necessary to set the port, as the click is passed
  405.     to the active window's handler.
  406. */
  407.  
  408. static DoKey (WHandler **h, char ch, Integer mods)
  409. {
  410. register ProcPtr    p;
  411.  
  412.     if (h != nil)
  413.     {
  414.         if ((p = (**h).whKey) != nil)
  415.            ((void (*)(char, Integer)) p) (ch, mods);
  416.     }
  417. }
  418.  
  419.  
  420. /*
  421.     Call the window updating procedure, passing to it an indicator whether
  422.     the window has been resized or not.  Then clear the flag, assuming
  423.     the update proc took whatever action was necessary to respond to
  424.     resizing.
  425.  
  426.     If the handler doesn't have any update proc, the Begin/EndUpdate
  427.     stuff is still done, to clear the update region.  Otherwise the
  428.     Window Manager will keep generating update events for the window,
  429.     stalling updates of other windows.
  430.  
  431.     Make sure to save and restore the port, as it's not always the
  432.     active window that is updated.
  433. */
  434.  
  435. static DoUpdate (WHandler **h)
  436. {
  437. register WHandler    **rh;
  438. register ProcPtr    p;
  439. register GrafPtr    updPort;
  440. GrafPtr                tmpPort;
  441.  
  442.     if ((rh = h) != nil)
  443.     {
  444.         GetPort (&tmpPort);
  445.         SetPort (updPort = (**rh).whWind);
  446.         BeginUpdate (updPort);
  447.         if ((p = (**rh).whUpdate) != nil)
  448.         {
  449.             ((void (*)(Boolean)) p) ((**rh).whSized);
  450.             (**rh).whSized = false;
  451.         }
  452.         EndUpdate (updPort);
  453.         SetPort (tmpPort);
  454.     }
  455. }
  456.  
  457.  
  458. /*
  459.     Pass activate/deactivate notification to handler.  On activate,
  460.     set the port to the window coming active.  Normally this is done by
  461.     the user clicking in a window.
  462.  
  463.     *** BUT ***
  464.     Under certain conditions, a deactivate may be generated for a window
  465.     that has not had the port set to it by a preceding activate.  If an
  466.     application puts up window A, then window B in front of A, then
  467.     starts processing events, the first events will be a deactivate for A
  468.     and an activate for B.  Since it therefore can't be assumed the port
  469.     was set to A by an activate, the port needs to be set for deactivates
  470.     as well.
  471.  
  472.     This matters not a whit for the more usual cases that occur.  If a
  473.     deactivate for one window is followed by an activate for another, the
  474.     port will still be switched properly to the newly active window.  If
  475.     no activate follows the deactivate, the deactivated window is the last
  476.     one, and it doesn't matter what the port ends up set to, anyway.
  477. */
  478.  
  479. static DoActivate (WHandler **h, Boolean active)
  480. {
  481. register ProcPtr    p;
  482.  
  483.     if (h != nil)
  484.     {
  485.         SetPort ((**h).whWind);
  486.         if ((p = (**h).whActivate) != nil)
  487.             ((void (*)(Boolean)) p) (active);
  488.     }
  489. }
  490.  
  491.  
  492. /*
  493.     Execute a window handler's close box proc.  The close proc for
  494.     handlers for temp windows that want to remove themselves when the
  495.     window is closed can call SkelRmveWind to dispose of the window
  496.     and remove the handler from the window handler list.  Thus, windows
  497.     may be dynamically created and destroyed without filling up the
  498.     handler list with a bunch of invalid handlers.
  499.     
  500.     If the handler doesn't have a close proc, just hide the window.
  501.     The host should provide some way of reopening the window (perhaps
  502.     a menu selection).  Otherwise the window will be lost from user
  503.     control if it is hidden, since it won't receive user-initiated
  504.     events.
  505.  
  506.     This is called both for regular and dialog windows.
  507.  
  508.     Since the close box of only the active window may be clicked, it
  509.     is not necessary to set the port.
  510. */
  511.  
  512. static DoClose (WHandler **h)
  513. {
  514. register WHandler    **rh;
  515. register ProcPtr    p;
  516.  
  517.     if ((rh = h) != nil)
  518.     {
  519.         if ((p = (**rh).whClose) != nil)
  520.             ((void (*)(void)) p) ();
  521.         else
  522.             HideWindow ((**rh).whWind);
  523.     }
  524. }
  525.  
  526.  
  527. /*
  528.     Execute a window handler's clobber proc.  This is called both
  529.     for regular and dialog windows.
  530.  
  531.     Must save, set and restore port, since any window (not just active
  532.     one) may be clobbered at any time.
  533.  
  534.     Don't need to check whether handler is nil, as in other handler
  535.     procedures, since this is only called by SkelRmveWind with a
  536.     known-valid handler.
  537. */
  538.  
  539. static DoClobber (WHandler **h)
  540. {
  541. register ProcPtr    p;
  542. GrafPtr                tmpPort;
  543.  
  544.     GetPort (&tmpPort);
  545.     SetPort ((**h).whWind);
  546.     if ((p = (**h).whClobber) != nil)
  547.         ((void (*)(void)) p) ();
  548.     SetPort (tmpPort);
  549. }
  550.  
  551.  
  552. # ifdef    supportDialogs
  553.  
  554. /* -------------------------------------------------------------------- */
  555. /*                            Dialog-handling routines                    */
  556. /* -------------------------------------------------------------------- */
  557.  
  558.  
  559. /*
  560.     Handle event if it's for a (modeless) dialog.  The event must be one
  561.     of those that is passed to dialogs according to dlogEventMask.
  562.     This mask can be set so that disk-inserts, for instance, don't
  563.     get eaten up.
  564.  
  565.     Examine event and set port if dialog window is coming active (for
  566.     normal windows, DoActivate sets the port; there's no such thing
  567.     for dialogs, so it's done here.)  When this is done, the trio
  568.     of GetPort/SetPort/SetPort calls commented out below doesn't appear
  569.     to be necessary any longer.  If you want to be cautious, it doesn't
  570.     hurt to uncomment them...
  571. */
  572.  
  573. static DoDialog (EventRecord *theEvent)
  574. {
  575. register WHandler    **dh;
  576. DialogPtr            theDialog;
  577. register Integer    what;
  578. Integer                item;
  579. GrafPtr                tmpPort;
  580. WindowPeek            w;
  581.  
  582. /*
  583.     handle command keys before they get to IsDialogEvent
  584. */
  585.  
  586.     what = theEvent->what;
  587.     if((what == keyDown || what == autoKey) && (theEvent->modifiers & cmdKey))
  588.     {
  589.            DoMenuCommand (MenuKey (theEvent->message & charCodeMask));
  590.            return (true);
  591.     }
  592.     
  593.     if (((1 << what) & dlogEventMask) && IsDialogEvent (theEvent))
  594.     {
  595.         /* ugly programming award semi-finalist follows */
  596.         if (theEvent->what == activateEvt            /* if activate */
  597.             && (theEvent->modifiers & activeFlag)    /* and coming active */
  598.             && (w=(WindowPeek) theEvent->message)->windowKind
  599.                     == dialogKind)
  600.         {
  601.             SetPort ((GrafPtr) w);
  602.         }
  603.         if (DialogSelect (theEvent, &theDialog, &item)
  604.            && (dh = GetDHandler (theDialog)) != nil
  605.            && (**dh).whEvent != nil)
  606.         {
  607.             ProcPtr tmp;
  608.             /*GetPort (&tmpPort);*/
  609.             /*SetPort (theDialog);*/
  610.             
  611.             tmp = (**dh).whEvent;
  612.             ((void (*)(Integer, EventRecord *)) tmp)(item, theEvent);
  613.     
  614.             /*SetPort (tmpPort);*/
  615.         }
  616.         return (true);
  617.     }
  618.     return (false);
  619. }
  620.  
  621. # endif
  622.  
  623.  
  624. /* -------------------------------------------------------------------- */
  625. /*                            Event-handling routines                        */
  626. /* -------------------------------------------------------------------- */
  627.  
  628.  
  629. /*
  630.     Have either zoomed a window or sized it manually.  Invalidate
  631.     it to force an update and set the 'resized' flag in the window
  632.     handler true.  The port is assumed to be set to the port that changed
  633.     size.
  634. */
  635.  
  636. static TriggerUpdate (WHandler **h, GrafPtr grownPort)
  637. {
  638.     InvalRect (&grownPort->portRect);
  639.     if (h != nil)
  640.         (**h).whSized = true;
  641. }
  642.  
  643.  
  644. /*
  645.     Size a window.  If the window has a handler, use the grow limits
  646.     in the handler record, otherwise use the defaults.
  647.  
  648.     The portRect is invalidated to force an update event.  The handler's
  649.     update procedure should check the parameter passed to it to check
  650.     whether the window has changed size, if it needs to adjust itself to
  651.     the new size.  THIS IS A CONVENTION.  Update procs must notice grow
  652.     "events", there is no procedure specifically for such events.
  653.     
  654.     The clipping rectangle is not reset.  If the host application
  655.     keeps the clipping set equal to the portRect or something similar,
  656.     then it will have to arrange to treat window growing with more
  657.     care.
  658.  
  659.     Since the grow region of only the active window may be clicked,
  660.     it should not be necessary to set the port.
  661. */
  662.  
  663. static DoGrow (WHandler **h, GrafPtr growPort, Point startPt)
  664. {
  665. Rect                r;
  666. register Longint    growRes;
  667.  
  668.     if (h != nil)
  669.         r = (**h).whGrow;
  670.     else
  671.         r = growRect;    /* use default */
  672.  
  673.     /* grow result non-zero if size change    */
  674.  
  675.     if (growRes = GrowWindow (growPort, startPt, &r))
  676.     {
  677.         SizeWindow (growPort, LoWord (growRes), HiWord (growRes), false);
  678.         TriggerUpdate (h, growPort);
  679.     }
  680. }
  681.  
  682.  
  683. /*
  684.     Zoom the current window.  Very similar to DoGrow
  685.  
  686.     Since the zoombox of only the active window may be clicked,
  687.     it should not be necessary to set the port.
  688. */
  689.  
  690. static DoZoom (WHandler **h, GrafPtr zoomPort, short partCode)
  691. {
  692.     ZoomWindow (zoomPort, partCode, 0);
  693.     TriggerUpdate (h, zoomPort);
  694. }
  695.  
  696.  
  697. /*
  698.     General event handler
  699. */
  700.  
  701. static DoEvent (EventRecord *theEvent)
  702.  
  703. {
  704. Point                evtPt;
  705. GrafPtr                evtPort;
  706. register Integer    evtPart;
  707. register char        evtChar;
  708. register Integer    evtMods;
  709. register Longint    evtMsge;
  710. register WHandler    **h;
  711. Rect                r;
  712.  
  713. # ifdef    supportDialogs
  714.  
  715.     if(DoDialog (theEvent))
  716.         return;
  717.  
  718. # endif
  719.  
  720.     evtPt = theEvent->where;
  721.     evtMods = theEvent->modifiers;
  722.     evtMsge = theEvent->message;
  723.  
  724.     switch (theEvent->what)
  725.     {
  726.  
  727.         /*case nullEvent:
  728.             break;*/
  729. /*
  730.     Mouse click.  Get the window that the click occurred in, and the
  731.     part of the window.  GetWDHandler is called here, not GetWHandler, since
  732.     we need the handler for a window which might turn out to be a dialog
  733.     window, e.g., if the click is in a close box.
  734. */
  735.         case mouseDown:
  736.         {
  737.             evtPart = FindWindow (evtPt, &evtPort);
  738.             h = GetWDHandler (evtPort);
  739.  
  740.             switch (evtPart)
  741.             {
  742. /*
  743.     Click in a desk accessory window.  Pass back to the system.
  744. */
  745.                 case inSysWindow:
  746.                 {
  747.                     SystemClick (theEvent, evtPort);
  748.                     break;
  749.                 }
  750. /*
  751.     Click in menu bar.  Track the mouse and execute selected command,
  752.     if any.
  753. */
  754.                 case inMenuBar:
  755.                 {
  756.                     DoMenuCommand (MenuSelect (evtPt));
  757.                     break;
  758.                 }
  759. /*
  760.     Click in grow box.  Resize window.
  761. */
  762.                 case inGrow:
  763.                 {
  764.                     DoGrow (h, evtPort, evtPt);
  765.                     break;
  766.                 }
  767. /*
  768.     Click in title bar.  Drag the window around.  Leave at least
  769.     4 pixels visible in both directions.
  770.     Bug fix:  The window is selected first to make sure it's at least
  771.     activated (unless the command key is down-see Inside Macintosh).
  772.     DragWindow seems to call StillDown first, so that clicks in drag
  773.     regions while machine is busy don't otherwise bring window to front if
  774.     the mouse is already up by the time DragWindow is called.
  775. */
  776.                 case inDrag:
  777.                 {
  778.                     if (evtPort != FrontWindow () && (evtMods & cmdKey) == 0)
  779.                         SelectWindow (evtPort);
  780.                     r = screenPort->portRect;
  781.                     r.top += mBarHeight;            /* skip down past menu bar */
  782.                     InsetRect (&r, 4, 4);
  783.                     DragWindow (evtPort, evtPt, &r);
  784.                     break;
  785.                 }
  786. /*
  787.     Click in close box.  Call the close proc if the window has one.
  788. */
  789.                 case inGoAway:
  790.                 {
  791.                     if (TrackGoAway (evtPort, evtPt))
  792.                         DoClose (h);
  793.                     break;
  794.                 }
  795.  
  796. /*
  797.     Click in zoom box.  Track the click and then zoom the window if
  798.     necessary
  799. */
  800.                 case inZoomIn:
  801.                 case inZoomOut:
  802.                 {
  803.                     if (TrackBox (evtPort, evtPt, evtPart))
  804.                         DoZoom (h, evtPort, evtPart);
  805.                     break;
  806.                 }
  807. /*
  808.     Click in content region.  If the window wasn't frontmost (active),
  809.     just select it, otherwise pass the click to the window's mouse
  810.     click handler.
  811. */
  812.                 case inContent:
  813.                 {
  814.                     if (evtPort != FrontWindow ())
  815.                         SelectWindow (evtPort);
  816.                     else
  817.                         DoMouse (h, theEvent);
  818.                     break;
  819.                 }
  820.  
  821.             }
  822.             break;    /* mouseDown */
  823.         }
  824. /*
  825.     Key event.  If the command key was down, process as menu item
  826.     selection, otherwise pass the character and the modifiers flags
  827.     to the active window's key handler.
  828.  
  829.     If dialogs are supported, there's no check for command-key
  830.     equivalents, since that would have been checked in DoDialog.
  831. */
  832.         case keyDown:
  833.         case autoKey:
  834.         {
  835.             evtChar = evtMsge & charCodeMask;
  836.  
  837. # ifndef    supportDialogs
  838.  
  839.             if (evtMods & cmdKey)        /* try menu equivalent */
  840.             {
  841.                 DoMenuCommand (MenuKey (evtChar));
  842.                 break;
  843.             }
  844.  
  845. # endif
  846.  
  847.             DoKey (GetWHandler (FrontWindow ()), evtChar, evtMods);
  848.             break;
  849.         }
  850. /*
  851.     Update a window.
  852. */
  853.         case updateEvt:
  854.         {
  855.             DoUpdate (GetWHandler ((WindowPtr) evtMsge));
  856.             break;
  857.         }
  858. /*
  859.     Activate or deactivate a window.
  860. */
  861.         case activateEvt:
  862.         {
  863.             DoActivate (GetWHandler ((WindowPtr) evtMsge),
  864.                         ((evtMods & activeFlag) != 0));
  865.             break;
  866.         }
  867. /*
  868.     handle inserts of uninitialized disks
  869. */
  870.         case diskEvt:
  871.         {
  872.             if (HiWord (evtMsge) != noErr)
  873.             {
  874.                 DILoad ();
  875.                 (void) DIBadMount (diskInitPt, evtMsge);
  876.                 DIUnload ();
  877.             }
  878.             break;
  879.         }
  880.     }
  881. }
  882.  
  883.  
  884. /* -------------------------------------------------------------------- */
  885. /*                        Interface (public) Routines                        */
  886. /* -------------------------------------------------------------------- */
  887.  
  888.  
  889. /*
  890.     Initialize the various Macintosh Managers.
  891.     Set default upper limits on window sizing.
  892.     FlushEvents does NOT toss disk insert events, so that disks
  893.     inserted while the application is starting up don't result
  894.     in dead drives.
  895.  
  896.     noMasters is the number of times to call MoreMasters.  gzProc is
  897.     the address of a grow zone procedure to call if memory allocation
  898.     problems occur.  Pass nil if none to be used.
  899. */
  900.  
  901. SkelInit (int noMasters, ProcPtr gzProc)
  902. {
  903.     while (noMasters-- > 0)
  904.         MoreMasters ();
  905.  
  906.     if (gzProc != nil)
  907.         SetGrowZone (gzProc);
  908.  
  909.     MaxApplZone ();
  910.     FlushEvents (everyEvent - diskMask, 0 );
  911.     InitGraf (&(qd.thePort));
  912.     InitFonts ();
  913.     InitWindows ();
  914.     InitMenus ();
  915.     TEInit ();
  916.     InitDialogs (nil);        /* no restart proc */
  917.     InitCursor ();
  918. /*
  919.     Set upper limits of window sizing to machine screen size.  Allow
  920.     for the menu bar.
  921. */
  922.     GetWMgrPort (&screenPort);
  923.     growRect.right = screenPort->portRect.right;
  924.     growRect.bottom = screenPort->portRect.bottom - mBarHeight;
  925. }
  926.  
  927.  
  928. /*
  929.     Main loop.
  930.  
  931.     Task care of DA's with SystemTask.
  932.     Run background task if there is one.
  933.     If there is an event, check for an event hook.  If there isn't
  934.     one defined, or if there is but it returns false, call the
  935.     general event handler.  (Hook returns true if TransSkel should
  936.     ignore the event.)
  937.     If no event, call the "no-event" handler for the front window and for
  938.     any other windows with idle procedures that are always supposed
  939.     to run.  This is done in such a way that it is safe for idle procs
  940.     to remove the handler for their own window if they want (unlikely,
  941.     but...)  This loop doesn't check whether the window is really
  942.     a dialog window or not, but it doesn't have to, because such
  943.     things always have a nil idle proc.
  944.     
  945.     doneFlag is reset upon exit.  This allows SkelMain to be called
  946.     repeatedly, or recursively.
  947.  
  948.     Null events are examined (in SkelMain) and passed to the event
  949.     handler.  This is necessary to make sure, if dialogs are supported,
  950.     that DialogSelect gets called repeatedly, or the caret won't blink
  951.     if a dialog has any editText items.
  952.  
  953.     Null events are not passed to any event-inspecting hook that may
  954.     be installed.
  955. */
  956.  
  957. SkelMain (void)
  958. {
  959. EventRecord            theEvent;
  960. register WHandler    **wh, **wh2;
  961. register WindowPtr    w;
  962. Boolean                haveEvent;
  963. GrafPtr                tmpPort;
  964. register ProcPtr    p;
  965.  
  966.     DrawMenuBar();
  967.  
  968.     while (!doneFlag)
  969.     {    
  970.         SystemTask ();
  971.         if (pBkgnd != nil)
  972.             ((void (*)(void)) pBkgnd) ();
  973.  
  974. /*
  975.     Now watch carefully.  GetNextEvent calls SystemEvent to handle some
  976.     DA events, and returns false if the event was handled.  However, in
  977.     such cases the event record will still have the event that occurred,
  978.     *not* a null event, as you might reasonably expect.  So it's not
  979.     enough to look at haveEvent.
  980.  
  981.     Previous versions figured (wrongly) that haveEvent==false meant a null
  982.     event had occurred, and passed it through to DoEvent and DoDialog, so
  983.     that caret-blinking in dialog TextEdit items would occur.  But cmd-key
  984.     equivalents while DA windows were in front, in particular, allowed
  985.     already-processed DA events to get into DoEvent (because haveEvent
  986.     was false), and they got handled twice because when the event record
  987.     was examined, lo and behold, it had a cmd-key event!  So now this
  988.     logic is used:
  989.  
  990.     If have a real event, and there's no event hook or there is but it
  991.     doesn't handle the event, OR if the "non-event" is a true nullEvent,
  992.     then process it.
  993. */
  994.             
  995.         haveEvent = GetNextEvent (eventMask, &theEvent);
  996.  
  997.         if ((haveEvent && (pEvent == nil || (*pEvent)(&theEvent) == false))
  998.                 || theEvent.what == nullEvent)
  999.             DoEvent(&theEvent);
  1000.  
  1001. /*
  1002.     Run applicable idle procs.  Make sure to save and restore the port,
  1003.     since idle procs for the non-active window may be run.
  1004. */
  1005.  
  1006.         if (!haveEvent)
  1007.         {
  1008.             GetPort (&tmpPort);
  1009.             for (wh = whList; wh != nil; wh = wh2)
  1010.             {
  1011.                 wh2 = (**wh).whNext;
  1012.                 w = (**wh).whWind;
  1013.                 if ( (w == FrontWindow () || !(**wh).whFrontOnly ) )
  1014.                 {
  1015.                     SystemTask ();
  1016.                     if ((p = (**wh).whIdle) != nil)
  1017.                     {
  1018.                         SetPort (w);
  1019.                         ((void (*)(void)) p) ();
  1020.                     }
  1021.                 }
  1022.             }
  1023.             SetPort (tmpPort);
  1024.         }
  1025.     }
  1026.     doneFlag = false;
  1027. }
  1028.  
  1029.  
  1030. /*
  1031.     Tell SkelMain to stop
  1032. */
  1033.  
  1034. SkelWhoa (void) { doneFlag = true; }
  1035.  
  1036.  
  1037. /*
  1038.     Clobber all the menu, window and dialog handlers
  1039. */
  1040.  
  1041. SkelClobber (void)
  1042. {
  1043.     while (whList != nil)
  1044.         SkelRmveWind ((**whList).whWind);
  1045.  
  1046.     while (mhList != nil)
  1047.         SkelRmveMenu (GetMHandle((**mhList).mhID));
  1048. }
  1049.  
  1050.  
  1051. /* -------------------------------------------------------------------- */
  1052. /*                        Menu-handler interface routines                    */
  1053. /* -------------------------------------------------------------------- */
  1054.  
  1055.  
  1056. /*
  1057.     Install handler for a menu.  Remove any previous handler for it.
  1058.     Pass the following parameters:
  1059.  
  1060.     theMenu    Handle to the menu to be handled.  Must be created by host.
  1061.     pSelect    Proc that handles selection of items from menu.  If this is
  1062.             nil, the menu is installed, but nothing happens when items
  1063.             are selected from it.
  1064.     pClobber Proc for disposal of handler's data structures.  Usually
  1065.             nil for menus that remain in menu bar until program
  1066.             termination.
  1067.     
  1068.     The menu is installed, and also drawn in the menu bar if drawBar true.
  1069.     
  1070.     Return 0 if no handler could be allocated, non-zero if successful.
  1071. */
  1072.  
  1073. SkelMenu (MenuHandle theMenu, ProcPtr pSelect, ProcPtr pClobber, Boolean drawBar)
  1074. {
  1075. register MHandler    **mh;
  1076.  
  1077.     mhClobOnRmve = false;
  1078.     SkelRmveMenu (theMenu);
  1079.     mhClobOnRmve = true;
  1080.  
  1081.     if ((mh = New (MHandler)) != nil)
  1082.     {
  1083.         (**mh).mhNext = mhList;
  1084.         mhList = mh;
  1085.         (**mh).mhID = (**theMenu).menuID;    /* get menu id number */
  1086.         (**mh).mhSelect = pSelect;            /* install selection handler */
  1087.         (**mh).mhClobber = pClobber;        /* install disposal handler */
  1088.         InsertMenu (theMenu, 0);            /* put menu at end of menu bar */
  1089.     }
  1090.     if (drawBar)
  1091.         DrawMenuBar ();
  1092.     return (mh != nil);
  1093. }
  1094.  
  1095.  
  1096. /*
  1097.     Remove a menu handler.  This calls the handler's disposal routine
  1098.     and then takes the handler out of the handler list and disposes
  1099.     of it.
  1100.  
  1101.     Note that the menu MUST be deleted from the menu bar before calling
  1102.     the clobber proc, because the menu bar will end up filled with
  1103.     garbage if the menu was allocated with NewMenu (see discussion of
  1104.     DisposeMenu in Menu Manager section of Inside Macintosh).
  1105. */
  1106.  
  1107. SkelRmveMenu (MenuHandle theMenu)
  1108. {
  1109. register Integer    mID;
  1110. register MHandler    **h, **h2;
  1111. register ProcPtr    p;
  1112.  
  1113.     mID = (**theMenu).menuID;
  1114.     if (mhList != nil)                /* if list empty, ignore */
  1115.     {
  1116.         if ((**mhList).mhID == mID)    /* is it the first element? */
  1117.         {
  1118.             h2 = mhList;
  1119.             mhList = (**mhList).mhNext;
  1120.         }
  1121.         else
  1122.         {
  1123.             for (h = mhList; h != nil; h = h2)
  1124.             {
  1125.                 h2 = (**h).mhNext;
  1126.                 if (h2 == nil)
  1127.                     return;                        /* menu not in list! */
  1128.                 if ((**h2).mhID == mID)            /* found it */
  1129.                 {
  1130.                     (**h).mhNext = (**h2).mhNext;
  1131.                     break;
  1132.                 }
  1133.             }
  1134.         }
  1135.         DeleteMenu (mID);
  1136.         DrawMenuBar ();
  1137.         if (mhClobOnRmve && (p = (**h2).mhClobber) != nil)
  1138.             ((void (*)(MenuHandle)) p) (theMenu); /* call disposal routine */
  1139.         DisposHandle ((Handle) h2);                /* get rid of handler record */
  1140.     }
  1141. }
  1142.  
  1143.  
  1144. /*
  1145.     Install a handler for the Apple menu.
  1146.     
  1147.     SkelApple is called if TransSkel is supposed to handle the apple
  1148.     menu itself.  aboutTitle is the title of the first item.  If nil,
  1149.     then only desk accessories are put into the menu.  If not nil, then
  1150.     the title is entered as the first item, followed by a gray line,
  1151.     then the desk accessories.
  1152.  
  1153.     SkelApple does not cause the menubar to be drawn, so if the Apple
  1154.     menu is the only menu, DrawMenuBar must be called afterward.
  1155.  
  1156.     No value is returned, unlike SkelMenu.  It is assumed that SkelApple
  1157.     will be called so early in the application that the call the SkelMenu
  1158.     is virtually certain to succeed.  If it doesn't, there's probably
  1159.     little hope for the application anyway.
  1160. */
  1161.  
  1162. SkelApple (StringPtr aboutTitle, ProcPtr aboutProc)
  1163. {
  1164.     appleID = 1;
  1165.     appleMenu = NewMenu (appleID, "\p\024");    /* 024 = apple character */
  1166.     if (aboutTitle != nil)
  1167.     {
  1168.         doAbout = true;
  1169.         AppendMenu (appleMenu, aboutTitle);    /* add About... item title */
  1170.         AppendMenu (appleMenu, "\p(-");        /* add gray line */
  1171.         appleAboutProc = aboutProc;
  1172.     }
  1173.     AddResMenu (appleMenu, 'DRVR');        /* add desk accessories */
  1174.     (void) SkelMenu (appleMenu, DoAppleItem, DoAppleClobber, false);
  1175. }
  1176.  
  1177.  
  1178. /* -------------------------------------------------------------------- */
  1179. /*                    Window-handler interface routines                    */
  1180. /* -------------------------------------------------------------------- */
  1181.  
  1182.  
  1183. /*
  1184.     Install handler for a window and set current port to it.  Remove
  1185.     any previous handler for it.  Pass the following parameters:
  1186.  
  1187.     theWind    Pointer to the window to be handled.  Must be created by host.
  1188.     pMouse    Proc to handle mouse clicks in window.  The proc will be
  1189.             passed the point (in local coordinates), the time of the
  1190.             click, and the modifier flags word.
  1191.     pKey    Proc to handle key clicks in window.  The proc will be passed
  1192.             the character and the modifier flags word.
  1193.     pUpdate    Proc for updating window.  TransSkel brackets calls to update
  1194.             procs with calls to BeginUpdate and EndUpdate, so the visRgn
  1195.             is set up correctly.  A flag is passed indicating whether the
  1196.             window was resized or not.  BY CONVENTION, the entire portRect
  1197.             is invalidated when the window is resized.  That way, the
  1198.             handler's update proc can redraw the entire content region
  1199.             without interference from BeginUpdate/EndUpdate.  The flag
  1200.             is set to false after the update proc is called; the
  1201.             assumption is made that it will notice the resizing and
  1202.             respond appropriately.
  1203.     pActivate Proc to execute when window is activated or deactivated.
  1204.             A boolean is passed to it which is true if the window is
  1205.             coming active, false if it's going inactive.
  1206.     pClose    Proc to execute when mouse clicked in close box.  Useful
  1207.             mainly to temp window handlers that want to know when to
  1208.             self-destruct (with SkelRmveWind).
  1209.     pClobber Proc for disposal of handler's data structures
  1210.     pIdle    Proc to execute when no events are pending.
  1211.     frontOnly True if pIdle should execute on no events only when
  1212.             theWind is frontmost, false if executes all the time.  Note
  1213.             that if it always goes, everything else may be slowed down!
  1214.  
  1215.     If a particular procedure is not needed (e.g., key events are
  1216.     not processed by a handler), pass nil in place of the appropriate
  1217.     procedure address.
  1218.     
  1219.     Return zero if no handler could be allocated, non-zero if successful.
  1220.     If zero is returned, the port will not have changed.
  1221. */
  1222.  
  1223. SkelWindow (WindowPtr theWind, ProcPtr pMouse, ProcPtr pKey, ProcPtr pUpdate, ProcPtr pActivate, ProcPtr pClose, ProcPtr pClobber, ProcPtr pIdle, Boolean frontOnly)
  1224. {
  1225. register WHandler    **hHand, *hPtr;
  1226.  
  1227.     whClobOnRmve = false;
  1228.     SkelRmveWind (theWind);
  1229.     whClobOnRmve = true;
  1230.  
  1231. /*
  1232.     Get new handler, attach to list of handlers.  It is attached to the
  1233.     beginning of the list, which is simpler; the order is presumably
  1234.     irrelevant to the host, anyway.
  1235. */
  1236.  
  1237.     if ((hHand = New (WHandler)) != nil)
  1238.     {
  1239.         (**hHand).whNext = whList;
  1240.         whList = hHand;
  1241.  
  1242. /*
  1243.     Fill in handler fields
  1244. */
  1245.  
  1246.         hPtr = *hHand;
  1247.         hPtr->whWind = theWind;
  1248.         hPtr->whMouse = pMouse;
  1249.         hPtr->whKey = pKey;
  1250.         hPtr->whUpdate = pUpdate;
  1251.         hPtr->whActivate = pActivate;
  1252.         hPtr->whClose = pClose;
  1253.         hPtr->whClobber = pClobber;
  1254.         hPtr->whIdle = pIdle;
  1255.         hPtr->whFrontOnly = frontOnly;
  1256.         hPtr->whSized = false;
  1257.         hPtr->whGrow = growRect;
  1258.         SetPort (theWind);
  1259.     }
  1260.     return (hHand != nil);
  1261. }
  1262.  
  1263.  
  1264. /*
  1265.     Remove a window handler.  This calls the handler's disposal routine
  1266.     and then takes the handler out of the handler list and disposes
  1267.     of it.
  1268.  
  1269.     SkelRmveWind is also called by SkelRmveDlog.
  1270.  
  1271.     Note that if the window cache variable is set to the window whose
  1272.     handler is being clobbered, the variable must be zeroed.
  1273. */
  1274.  
  1275. SkelRmveWind (WindowPtr theWind)
  1276. {
  1277. register WHandler    **h, **h2;
  1278.  
  1279.     if (theWind == oldWindow)
  1280.         oldWindow = nil;
  1281.  
  1282.     if (whList != nil)        /* if list empty, ignore */
  1283.     {
  1284.         if ((**whList).whWind == theWind)    /* is it the first element? */
  1285.         {
  1286.             h2 = whList;
  1287.             whList = (**whList).whNext;
  1288.         }
  1289.         else
  1290.         {
  1291.             for (h = whList; h != nil; h = h2)
  1292.             {
  1293.                 h2 = (**h).whNext;
  1294.                 if (h2 == nil)
  1295.                     return;                        /* theWind not in list! */
  1296.                 if ((**h2).whWind == theWind)    /* found it */
  1297.                 {
  1298.                     (**h).whNext = (**h2).whNext;
  1299.                     break;
  1300.                 }
  1301.             }
  1302.         }
  1303.         if (whClobOnRmve)
  1304.             DoClobber (h2);        /* call disposal routine */
  1305.         DisposHandle ((Handle) h2);        /* get rid of handler record */
  1306.     }
  1307. }
  1308.  
  1309.  
  1310. # ifdef    supportDialogs
  1311.  
  1312. /* -------------------------------------------------------------------- */
  1313. /*                    Dialog-handler interface routines                    */
  1314. /* -------------------------------------------------------------------- */
  1315.  
  1316.  
  1317. /*
  1318.     Install a handler for a modeless dialog window and set the port
  1319.     to it.  Remove any previous handler for it. SkelDialog calls
  1320.     SkelWindow as a subsidiary to install a window handler, then sets
  1321.     the event procedure on return.
  1322.  
  1323.     Pass the following parameters:
  1324.  
  1325.     theDialog    Pointer to the dialog to be handled.  Must be created
  1326.             by host.
  1327.     pEvent    Event-handling proc for dialog events.
  1328.     pClose    Proc to execute when mouse clicked in close box.  Useful
  1329.             mainly to dialog handlers that want to know when to
  1330.             self-destruct (with SkelRmveDlog).
  1331.     pClobber Proc for disposal of handler's data structures
  1332.  
  1333.     If a particular procedure is not needed, pass nil in place of
  1334.     the appropriate procedure address.
  1335.     
  1336.     Return zero if no handler could be allocated, non-zero if successful.
  1337.     If zero is returned, the port will not have changed.
  1338. */
  1339.  
  1340. SkelDialog (DialogPtr theDialog, ProcPtr pEvent, ProcPtr pClose, ProcPtr pClobber)
  1341. {
  1342. int        swOk;
  1343.  
  1344.     if (SkelWindow (theDialog, nil, nil, nil, nil, pClose, pClobber, nil, false))
  1345.     {
  1346.         (**GetWDHandler (theDialog)).whEvent = pEvent;
  1347.         return (1);
  1348.     }
  1349.     return (0);
  1350. }
  1351.  
  1352.  
  1353. /*
  1354.     Remove a dialog and its handler
  1355. */
  1356.  
  1357. SkelRmveDlog (DialogPtr theDialog)
  1358. {
  1359.     SkelRmveWind (theDialog);
  1360. }
  1361.  
  1362. # endif
  1363.  
  1364.  
  1365. /* -------------------------------------------------------------------- */
  1366. /*                    Miscellaneous interface routines                    */
  1367. /* -------------------------------------------------------------------- */
  1368.  
  1369.  
  1370. /*
  1371.     Override the default sizing limits for a window, or, if theWind
  1372.     is nil, reset the default limits used by SkelWindow.
  1373. */
  1374.  
  1375. SkelGrowBounds (WindowPtr theWind, Integer hLo, Integer vLo, Integer hHi, Integer vHi)
  1376. {
  1377. register WHandler    **h;
  1378. Rect                r;
  1379.  
  1380.     if (theWind == nil)
  1381.         SetRect (&growRect, hLo, vLo, hHi, vHi);
  1382.     else if ((h = GetWHandler (theWind)) != nil)
  1383.     {
  1384.         SetRect (&r, hLo, vLo, hHi, vHi);
  1385.         (**h).whGrow = r;
  1386.     }
  1387. }
  1388.  
  1389.  
  1390. /*
  1391.     Set the event mask.
  1392. */
  1393.  
  1394. SkelEventMask (Integer mask)
  1395. {
  1396.     eventMask = mask;
  1397. }
  1398.  
  1399.  
  1400. /*
  1401.     Return the event mask.
  1402. */
  1403.  
  1404. SkelGetEventMask (Integer *mask)
  1405. {
  1406.     *mask = eventMask;
  1407. }
  1408.  
  1409.  
  1410. /*
  1411.     Install a background task.  If p is nil, the current task is
  1412.     disabled.
  1413. */
  1414.  
  1415. SkelBackground (ProcPtr p)
  1416. {
  1417.     pBkgnd = p;
  1418. }
  1419.  
  1420.  
  1421. /*
  1422.     Return the current background task.  Return nil if none.
  1423. */
  1424.  
  1425. SkelGetBackground (ProcPtr *p)
  1426. {
  1427.     *p = pBkgnd;
  1428. }
  1429.  
  1430.  
  1431. /*
  1432.     Install an event-inspecting hook.  If p is nil, the hook is
  1433.     disabled.
  1434. */
  1435.  
  1436. SkelEventHook (Boolean (*p )())
  1437. {
  1438.     pEvent = p;
  1439. }
  1440.  
  1441.  
  1442. /*
  1443.     Return the current event-inspecting hook.  Return nil if none.
  1444. */
  1445.  
  1446. SkelGetEventHook (Boolean (**p )())
  1447. {
  1448.     *p = pEvent;
  1449. }
  1450.  
  1451.  
  1452. # ifdef    supportDialogs
  1453.  
  1454. /*
  1455.     Set the mask for event types that will be passed to dialogs.
  1456.     Bit 1 is always set, so that null events will be examined.
  1457.     (If this is not done, the caret does not blink in editText items.)
  1458. */
  1459.  
  1460. SkelDlogMask (Integer mask)
  1461. {
  1462.     dlogEventMask = mask | 1;
  1463. }
  1464.  
  1465.  
  1466. /*
  1467.     Return the current dialog event mask.
  1468. */
  1469.  
  1470. SkelGetDlogMask (Integer *mask)
  1471. {
  1472.     *mask = dlogEventMask;
  1473. }
  1474.  
  1475. # endif
  1476.